package leetcode.f1t100;

/**
 * 数组删除某个值
 * https://leetcode.com/problems/remove-element/
 * @Author lichongxiao
 * @Date 2022/10/8 14:08
 */
public class Q27_RemoveElement {
    public int removeElement(int[] nums, int val) {
        int index = 0;
        for (int num : nums){
            if(num != val){
                nums[index++] = num;
            }
        }
        return index;
    }

    public static void main(String[] args) {
        int[] nums = new int[]{1,1,1,1,1};
        int count = new Q27_RemoveElement().removeElement(nums,1);
        for (int i = 0; i < count; i++) {
            System.out.println(nums[i]);
        }
    }
}
